package org.example;

import org.example.tools.jdbcUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/main")
public class mainApplication extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//       判断是否有登录，采用检查session中是否有保存有username信息
        HttpSession session = req.getSession();
//        如果session中没有用户名信息，则让回到登录页面去登录
        if (session.getAttribute("username") == null) {
            //密码错误，重定向登录
            req.setAttribute("errorMessage","尚未登录");
            //请求转发
            req.getRequestDispatcher("/loginError.jsp").forward(req,resp);
        }
//        否则，则正常进入main.jsp
        else {
            resp.sendRedirect("main.jsp");
        }
    }
}
